//
//  AnimationBootcamp_26.swift
//  SwiftUiExercise
//
//  Created by 徐鹏 on 2023/7/1.
//

import SwiftUI

struct AnimationBootcamp_26: View {
    
    @State var isAnimated:  Bool = false
    @State var isAnimated2: Bool = false
    
    var body: some View {
        VStack{
            Button("Button") {
                withAnimation(Animation
                    .default
                    .repeatForever(autoreverses: true)
                    //.repeatCount(10,autoreverses: true)
                ){
                    isAnimated.toggle()
                }
               
            }
            
            Button("Button2") {
                isAnimated2.toggle()
            }
            
            Spacer()
            
            RoundedRectangle( cornerRadius: isAnimated ? 50 : 25)
                .fill(isAnimated ? Color.red : Color.green)
                .frame(
                    width: isAnimated ? 100 : 300,
                    height: isAnimated ? 100 : 300
                )
                .rotationEffect(Angle(degrees: isAnimated ? 360 : 0))
                .offset(y : isAnimated ? 300 : 0)
            
            
            RoundedRectangle( cornerRadius: isAnimated2 ? 50 : 25)
                .fill(isAnimated2 ? Color.red : Color.green)
                .frame(
                    width: isAnimated2 ? 100 : 300,
                    height: isAnimated2 ? 100 : 300
                )
                .rotationEffect(Angle(degrees: isAnimated ? 360 : 0))
                .offset(y : isAnimated2 ? 300 : 0)
                .animation(Animation
                    .default
                    .repeatForever(
                        autoreverses: true
                    ))
               
            
            Spacer()
        }
    }
}

struct AnimationBootcamp_26_Previews: PreviewProvider {
    static var previews: some View {
        AnimationBootcamp_26()
    }
}
